﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Harkon.AppServer.cOne.Service;
using System.Threading;
using ClusterComponentA;

namespace ClusterComponentB
{
    public interface IWillUseRemotely : IService
    {

    }

    public class WillUseRemotely : AbstractService, IWillUseRemotely
    {
        public IWillBeUsed Target { get; set; }
        Thread t = null;

        public override bool Init()
        {
            if (base.Init())
            {
                t = new Thread(Run);
                t.Name = "ClusterTest";
                t.IsBackground = true;
                return true;
            }
            return false;
        }

        public override bool Start()
        {
            if (base.Start())
            {
                t.Start();
                return true;
            }
            return false;
        }

        private void Run()
        {
            Thread.Sleep(10000);
            ADedicatedBusinessObject obj = new ADedicatedBusinessObject { CreationTime = DateTime.Now, InitialString = "Hello " };
            ADedicatedBusinessObject retrievedObj = Target.AppendStringToObject(obj, "World!");
            TimeSpan delta = DateTime.Now - retrievedObj.CreationTime;
            Console.WriteLine("Object alteration took {0}ms -> Result:{1}", delta.TotalMilliseconds, retrievedObj.ToString());
        }
    }


}
